package d8_httpThreadPool;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Server {
    public static List<Socket> onLineSockets = new ArrayList<>();

    public static void main(String[] args) throws IOException {
        System.out.println("Server started......");
        ServerSocket serverSocket = new ServerSocket(8080);//新建端口
        //创建线程池
        ThreadPoolExecutor pool = new ThreadPoolExecutor(16*2,16*2,0, TimeUnit.SECONDS,new LinkedBlockingQueue<Runnable>(2),
                Executors.defaultThreadFactory(),new ThreadPoolExecutor.AbortPolicy());


        while (true) {
        Socket socket = serverSocket.accept();//接口接受连接
            ServerReaderRunnable srt = new ServerReaderRunnable(socket);
            pool.execute(srt);
        }
    }
}
